package org.liuwei.concucrent.base03.RentrantLock09;

import java.util.concurrent.locks.LockSupport;

/**
 * 
 * @Title: LockSupport01.java
 * @Package org.liuwei.concucrent.base03.RentrantLock09
 * @Description: TODO （系统层面的锁挂起)
 * @author 刘伟 15818570028@163.com
 * @date 2015年8月21日 上午9:57:14
 * @version V1.0
 */
public class LockSupport01 {
	public static void main(String[] args) throws Exception {
		t1();
	}

	private static void t1() {
		Thread thread = Thread.currentThread();

		LockSupport.unpark(thread);

		System.out.println("a");
		LockSupport.park();
		System.out.println("b");
		LockSupport.park();
		System.out.println("c");
	}

	public static void t2() throws Exception {
		Thread t = new Thread(new Runnable() {
			private int count = 0;

			public void run() {
				long start = System.currentTimeMillis();
				long end = 0;

				while ((end - start) <= 1000) {
					count++;
					end = System.currentTimeMillis();
				}

				System.out.println("after 1 second.count=" + count);

				// 等待或许许可
				LockSupport.park();
				System.out.println("thread over."
						+ Thread.currentThread().isInterrupted());

			}
		});

		t.start();

		Thread.sleep(2000);

		// 中断线程
		t.interrupt();

		System.out.println("main over");
	}
}
